package com.dianpingmedia.simulate.controller;


import com.alibaba.fastjson.JSON;
import com.dianpingmedia.LogAspect;
import com.dianpingmedia.common.DspID;
import com.dianpingmedia.common.SimulateConstant;
import com.dianpingmedia.common.utils.MiscUtil;
import com.dianpingmedia.simulate.annotation.DspId;
import com.dianpingmedia.simulate.annotation.Strategy;
import com.dianpingmedia.simulate.configuration.SimulateConfiguration;
import com.dianpingmedia.simulate.model.DPPlanEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;


@Strategy
public class StrategyController {
    private final Logger LOGGER = LoggerFactory.getLogger(LogAspect.class.getSimpleName());

    @Autowired
    SimulateConfiguration configuration;

    /**
     * 设置个性化属性
     *
     * @param request
     * @return 返回个性推送地址
     */
    @DspId(value = DspID.ZMT_DSP_ID)
    public String transmitFromZMT(DPPlanEntity.Request request) {
        request.setChannelId(configuration.getZmtConfiguration().getChannel_id());
        request.setSign(MiscUtil.zmengSign(request));
        LOGGER.info("Converted data:"+ JSON.toJSONString(request));
        return SimulateConstant.PUSH_ZMT_NEW_PLAN;
    }

    /**
     * 设置讯飞个性化属性
     *
     * @param request
     * @return
     */
    @DspId(value = DspID.IFLY_DSP_ID)
    public String transmitFromIFly(DPPlanEntity.Request request) {
        request.setSign(MiscUtil.iFlySign(request, configuration.iFlyConfiguration.getSecret_key()));
        LOGGER.info("Converted data:"+ JSON.toJSONString(request));
        return SimulateConstant.PUSH_IFLY_NEW_PLAN;
    }
}
